package com.yunchuang.service;

import com.yunchuang.common.FileListener;
import com.yunchuang.constant.FileStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * 文件监听
 *
 * @author ItJiange
 * @date 2023/10/20
 */
public class FileListenerService extends FileListener {
    private final Logger logger= LoggerFactory.getLogger("logback");
    private final FileUploadService fileUploadService = new FileUploadService();
    @Override
    public void onFileCreate(File file) {
        fileUploadService.sendFileMessage(file, FileStatus.CREATE.getDesc());
        logger.info("创建文件 : " + file.getAbsolutePath());
    }

    @Override
    public void onFileChange(File file) {
        fileUploadService.sendFileMessage(file, FileStatus.CHANGE.getDesc());
        logger.info("修改文件 : " + file.getAbsolutePath());
    }

    @Override
    public void onFileDelete(File file) {
        fileUploadService.sendFileMessage(file, FileStatus.DELETE.getDesc());
        logger.info("删除文件 : " + file.getAbsolutePath());
    }
}
